package com.diandian.backend.jingdong.home.exchange.controller;

import com.diandian.backend.jingdong.home.exchange.req.BatchQueryUseableInfoReq;
import com.diandian.backend.jingdong.home.exchange.service.BusinessJingdongTokenService;
import com.diandian.backend.jingdong.home.exchange.service.BusinessStockAvailableSaleService;
import com.diandian.base.boot.starter.response.BaseResult;
import com.diandian.base.boot.starter.util.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * 库存-商品可售API
 */
@RestController
@RequestMapping("/business/stock/available/sale")
public class BusinessStockAvailableSaleController {

    @Autowired
    private BusinessStockAvailableSaleService stockAvailableSaleService;

    @Autowired
    private BusinessJingdongTokenService businessJingdongTokenService;

    /**
     * 批量查询商品库存及可售状态信息
     *
     * @return
     * @throws Exception
     */
    @PostMapping("/queryOpenUseable")
    public BaseResult queryOpenUseable(@RequestHeader(value = "appKey") String appKey,
                                       @RequestHeader(value = "appSecret") String appSecret,
                                       @RequestHeader(value = "token", required = false) String token,
                                       @RequestHeader(value = "operator") String operator,
                                       @RequestHeader(value = "belong") String belong,
                                       @RequestBody BatchQueryUseableInfoReq data) throws Exception {

        String innerToken = (token == null || "".equals(token)) ? businessJingdongTokenService.getToken(appKey) : token;
        return ResultUtil.makeResult(stockAvailableSaleService.queryOpenUseable(appKey, appSecret, innerToken, belong, data));
    }
}
